package com.im.business.api.group;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Created leijun
 * @Date 2021/10/16 8:06 上午
 */
public class DataSourceManager {

    private SqlSessionFactory sqlSessionFactory;

    public void init() throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    }

    private static class Singleton{
        private static DataSourceManager instance = new DataSourceManager();
    }

    public static DataSourceManager getInstance() {
        return Singleton.instance;
    }

    public SqlSessionFactory getSqlSessionFactory() {
        return sqlSessionFactory;
    }
}
